#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib,urllib2,re,os,xbmc

#author:
#elypter
#-mail:elypter@yahoo.de
#




def check(url,divx):
	#not used atm
	if url.rfind(divx):
		return 1
	else:
		return 0
def get_regexp(divx):
	return '(http\://'+divx.replace('.','\\.')+'/file\-[^/<>"]*\.[0-9a-zA-Z]*)'
def get_name(divx):
	return divx
def join(id,divx):
	return id
def get_link1(url,divx):
	#takes an videopage-url of megavideo
	#
	#returnes the service/mirror name, the url that will be passed over to get_link2, the url of the verification code
	
	req = urllib2.Request(url)
	req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
	response = urllib2.urlopen(req)
	page=response.read()
	response.close()
	
	#print page
	
	#link = re.compile('type="video/divx" src="([^<>"]*)"',re.I).findall(page)
	link = re.compile('\<embed[^<>]*src="([^<>"]*)"',re.I|re.DOTALL).findall(page)
	
	if link!=None and len(link)>0:
		return ("got",link[0],'','','','',divx)
	else:
		return ("fail",'','','','','',divx)

def get_link2(param,code,divx):
	#should take the url that get_link1 returned
	#
	#returnes the video url
	return ("got",param,'','','','',divx)
